export async function handleErr(ctx, next) {
  try {
    await next();
  } catch (e) {
    console.log(e);
    if (e.statusCode) {
      ctx.status = e.statusCode;
      ctx.body = e.message;
    } else if (e.status === 400) {
      ctx.status = e.status;
      ctx.body = {
        errMsg: e.message,
      };
    } else {
      console.log("err", e);
      ctx.status = 500;
      ctx.body = "未知错误";
    }

    return;
  }
  if (ctx.status === 200 && !ctx.body) {
    ctx.body = {};
  }
}
